package edu.webarchitechture.bank.ejb3.util;

import edu.webarchitechture.bank.ejb3.exception.IllegalAccountTypeException;

/**
 * This helper class methods for getting and checking the domains of business entity variables.
 *
 * @author Inoka Dissanayaka.
 */
public final class DomainUtil {
    // The accountTypes array stores the valid account types.
    private static String[] accountTypes = {
            "Checking", "Savings", "Credit", "Money Market"
    };

    public static String[] getAccountTypes() {
        return accountTypes;
    }

    public static void checkAccountType(String type)
            throws IllegalAccountTypeException {
        boolean foundIt = false;

        for (String accountType : accountTypes) {
            if (accountType.equals(type)) {
                foundIt = true;
            }
        }

        if (!foundIt) {
            throw new IllegalAccountTypeException(type);
        }
    }

    public static boolean isCreditAccount(String type) {
        return type.equals("Credit");
    }
}